#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "menu.h"
#include <QUdpSocket>
#include <QMessageBox>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    void udp_init();
    void mesbox_init();
    void insert(const QString& plate, const QString& cardId, const QString& enterTime,
                const QString& parkTime, const QByteArray& pic);
    void insert2(const QString& status,const QString& plate, const QString& cardId, const QString& time, int fee,
                 const QString& parkTime, const QByteArray& pic, const QString& intime);
    QString time_calculation(QString time);
    QString time_calculation(QString in_time,QString out_time);
    QString queryInTimeByCarId(const QString& carId);

private slots:
    void on_menu_btn_clicked();

private slots:
  void processVideoDatagram1();
  void processVideoDatagram2();
  void processPlateDatagram1();
  void processPlateDatagram2();
  void warm(QAbstractButton *);
  void warm2(QAbstractButton *);

  void on_up_btn_clicked();

  void on_up_btn_pressed();

  void on_down_btn_pressed();

  void on_up_btn_released();

  void on_down_btn_released();

private:
    Ui::MainWindow *ui;
    menu p;
    QByteArray in_datagram;
    QByteArray out_datagram;
    QByteArray current_datagram;
    QHostAddress sender1; // ip
    quint16 senderPort1;  //端口
    QHostAddress sender2;
    quint16 senderPort2;
    QUdpSocket *udpSocketVideo1;
    QUdpSocket *udpSocketVideo2;
    QUdpSocket *udpSocketPlate1;
    QUdpSocket *udpSocketPlate2;
    QImage image1;
    QImage image2;
    QMessageBox * msgBox;
    QMessageBox * msgBox2;
    int index = 0;

    QString car_id;        //车牌
    QString card_id;       //卡号
    QString in_time;       //入场时间
    QString out_time;      //离场时间
    int stay_time;         //停车时长
    int fee;               //费用
    QString accuracy;      //确信率
    QString get_intime;    //获取的入场时间
    int total_num=400;     //总车位
    int rest_num=0;        //剩余车位

    // 数据库相关
    QSqlDatabase db;
    QSqlQuery query;
};
#endif // MAINWINDOW_H
